package com.alfayun.fiscalriskanalysis.another.indicator;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.alfayun.fiscalriskanalysis.another.report.Report;
import com.alfayun.fiscalriskanalysis.another.specification.indicator.IndicatorSpec;

public final class Indicator {

	private IndicatorSpec spec;

	private Map<String, Selector> selectors = new HashMap<>();
	private Map<String, Measure> measureMap = new HashMap<>();
	private List<Measure> measures;
	private Set<Alert> alerts;

	public Indicator(IndicatorSpec spec, Collection<Report> reports) {
		this.spec = spec;

		bindSelector(reports);
		calcMeasure();
		triggerAlert();
	}

	public Indicator(IndicatorSpec spec) {
		this.spec = spec;

		var selectorList = spec.buildSelectors();

		selectorList.forEach(it -> selectors.put(it.getName(), it));

		var measureList = spec.buildMeasures();
	}

	public void bindSelector(Collection<Report> reports) {
		selectors.values().forEach(it -> it.bindReport(reports));
	}

	public void calcMeasure() {

//		measures = spec.getAllMeasures().stream().map(e -> Measures.create(e, selectors)).collect(Collectors.toSet());
	}

	public void triggerAlert() {
//		alerts = spec.getAllAlerts().stream().map(e -> Alerts.create(e, measures)).collect(Collectors.toSet());
	}

}
